#ifndef __EAGLSupport_H__
#define __EAGLSupport_H__

#include "U2GLESSupport.h"

#ifdef __OBJC__
// Forward declarations
@class CAEAGLLayer;
@class UIWindow;
@class NSString;
typedef UIWindow *NativeWindowType;
#endif


U2EG_NAMESPACE_BEGIN


class EAGLWindow;
class EAGLESContext;
class U2GLESPBuffer;

template<class C> void removeDuplicates(C& c)
{
	std::sort(c.begin(), c.end());
	typename C::iterator p = std::unique(c.begin(), c.end());
	c.erase(p, c.end());
}

class _U2GLESPrivate EAGLSupport : public U2GLESSupport
{
	protected:
	public:
		EAGLSupport();
		virtual ~EAGLSupport();

		void start(void);
		void stop(void);
		void addConfig(void);
		U2String validateConfig(void);
		virtual U2String getDisplayName(void);
		CFDictionaryRef chooseGLConfig(const GLint *attribList, GLint *nElements);
		GLint getGLConfigAttrib(CFDictionaryRef fbConfig, GLint attribute, GLint *value);
		void * getProcAddress(const U2String& name);
		U2RenderWindow * createWindow(bool autoCreateWindow,
									   GLESRenderSystem *renderSystem,
									   const U2String& windowTitle);

		U2RenderWindow * newWindow(const U2String& name,
									unsigned int width, unsigned int height,
									bool fullScreen,
									const NameValuePairList *miscParams = 0);
		virtual U2GLESPBuffer * createPBuffer(PixelComponentType format,
											   size_t width, size_t height);

#ifdef __OBJC__
		bool portraitIsSupported(void);
		bool interfaceOrientationIsSupported(NSString *orientation);

		EAGLESContext * createNewContext(CFDictionaryRef &glconfig, CAEAGLLayer *drawable, EAGLSharegroup *group) const;
		CFDictionaryRef getGLConfigFromContext(EAGLESContext context);
		CFDictionaryRef getGLConfigFromDrawable(CAEAGLLayer *drawable, unsigned int *w, unsigned int *h);
#endif
		CFDictionaryRef selectGLConfig(const int* minAttribs, const int *maxAttribs);
};


U2EG_NAMESPACE_END


#endif
